
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>广告位管理</title>
     <#include "../StaticFile.ftl">
    <script>
    
    

    var toolbar = [{
            text:'广告位',
            iconCls:'icon-add',
            handler:function(){global.id=0;$('#dlg').dialog('open');
            clean();}
        }];
    
    </script>
</head>
<body>




<div id="cc" class="easyui-layout" style="width:100%;height:900px;">
     <#include "../Head.ftl">
     <#include "../Menu.ftl">
    <div data-options="region:'center',title:'数据显示区',split:true">
    
    
    <table id="dg" title="广告位管理" style="width:100%" data-options="
                singleSelect:true,
                autoRowHeight:false,
                pagination:true,
                url:'/banner/getdata',
                pageSize:20,toolbar:toolbar">
        <thead>
            <tr> <th field="id" width="120"  align="center">编号</th>
                <th field="title" width="120"  align="center">标题</th>
                <th data-options="field:'url',width:120,align:'center',formatter:formatIcon" >图片</th>
                 <th data-options="field:'pic_type',width:120,align:'center',formatter:formatImgType" ">图片类型</th>
                <th data-options="field:'intent_type',width:180,align:'center',formatter:formatType" >跳转类型</th>
                <th data-options="field:'intent_data',width:200,align:'center'" >跳转内容</th>
                <th data-options="field:'operation',width:280,align:'center',formatter:formatOperation" >操作</th>
            </tr>
        </thead>
    </table>
   
    <div id="dlg" class="easyui-dialog" title="添加轮播图" data-options="iconCls:'icon-save'" style="width:430px;height:280px;padding:10px;">
        
            <table cellpadding="5">
               
                <tr>
                    <td>标题:</td>
                    <td><input class="easyui-textbox" type="text" name="title" id="title" data-options="required:true,validType:'email'"></input></td>
                </tr>
                <tr>
                    <td>图片上传:</td>
                    <td>
                     <#assign name="banner">
                  <#assign img_flag="0">
                   <#include "../FileUpload.ftl">
                    </td>
                </tr>
              
                <tr>
                    <td>跳转类型:</td>
                    <td>
                    <select class="easyui-combobox"  id="content_type" name="content_type" >
                     <option value="1">链接</option>
                     <option value="2">应用</option>
                      <option value="3">页面</option>
                     <select>
                    </td>
                </tr>
                 <tr>
                    <td>内容:</td>
                    <td><input class="easyui-textbox" type="text"  id="content_target" name="content_target" ></td>
                </tr>
                </tr>
                 
            </table>
       
         <div style="text-align:center;padding:5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="addElement()">添加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">取消</a> 
         </div>
        </div>
       
      </div></div>
     <script>
     
     
     
            
             
        function clearForm(){
            $('#dlg').dialog('close'); 
        }
          $(function(){
            var pager = $('#dg').datagrid().datagrid('getPager');
            $('#dlg').dialog('close');
             })
               // get the pager of datagrid
               
         function doSearch(){
            $('#dg').datagrid('load',{
         
            });
            }
            var  global={id:0};
            function addElement()
            {
                var title=$("#title").textbox("getValue");
                if(!title){
                    alert("名称不能为空");
                    return;
                }
                var icon=$("#display_img_banner").attr("src");
                if(!icon)
                {
                    alert("图片不能为空");
                    return;
                }
                var content_target=$("#content_target").textbox("getValue");
               
                var content_type=$("#content_type").combobox("getValue");
                var reg=/^\d+$/;
                if(content_type==2 ||content_type==3)
                {
                    if(!content_target||!reg.test(content_target))
                    {
                        alert("内容必须不能为空并且为应用id")
                        return;
                    }
                }
                else
                {
                    var urlreg=/^(ftp|http|https):\/\/[^ "]+$/;
                    if(!content_target&&!urlreg.test(content_target))
                    {
                         alert("内容必须不能为空,并且必须是url格式")
                        return;
                    }
                  }
                  
                if(!window.confirm("确定要保存么？"))
                {
                    return;
                }
                $.ajax({
                type: "POST",
                  url: "/banner/add",
                  data:{
                  id:global.id,
                  title:title,
                  content_url:icon,
                  content_target:content_target,
                  content_type: content_type
                  },
                  success:function(data)
                  {
                    //var result=jQuery.parseJSON(data);
                    
                    doSearch();
                    $('#dlg').dialog('close');
                    
                  }
                  });
            }
            
            function clean()
            {
                     v$("#img_flag").val(0);
                     $("#title").textbox("setValue","");
                     $("#display_img_banner").attr("src","");
                     $("#content_target").textbox("setValue","");
                     $("#content_type").combobox("setValue",1);
                     $("#form_upload_banner").show();
                     $("#form_upload_successful_banner").hide();
                
            }
        function formatOperation(val,row)
        {
        
           
            if(row.status==0)
            {
                return '<a href="javascript:void(0)" class="easyui-linkbutton" style="padding-right:5px;" onclick="upadateStatus('+row.id+',1)">禁用</a><a href="javascript:void(0)" style="padding-right:5px;" class="easyui-linkbutton"  onclick="editElement('+
                row.id+')">编辑</a>'
            }
            else
            {
                return '<a href="javascript:void(0)" class="easyui-linkbutton"  style="padding-right:5px;" onclick="upadateStatus('+row.id+',0)">启用</a><a href="javascript:void(0)" style="padding-right:5px;" class="easyui-linkbutton" onclick="editElement('+row.id+
                ')">编辑</a>'
               
            }
           
        }
        
         function formatCreatDate(val,row)
        {
        
            return formatTime(val);
        }
        
         function upadateStatus(id,status)
            {
            
             if(!window.confirm("确定要修改么？"))
                {
                    return;
                }
                $.ajax({ type: "GET",
                url: "/banner/changestatus?id="+id+"&status="+status,
                success: function(data)
                 {
                    var returnData=jQuery.parseJSON(data);
                    if(returnData.code==0)
                    {
                    // $('#dlg').dialog('close');
                        doSearch(); 
                        
                      // alert("chenggong");
                    }
                  }});
            }
        function formatStatus(val,row)
        {
            if(val==0)
            {
                return "正常"
            }
            else
            {
                return "禁用"
            }
        }
         function formatIcon(val,row)
        {
           return "<img style='height:40px;width:40px;'  src='"+val+"'/>";
        } 
         function formatType(val,row)
        {
            if(val==1)
            {
           return "链接";
           }
           else if(val==2)
           {
           return "应用";
           }else
           {
            return "页面";
           }
        } 
         function formatImgType(val,row)
        {
            if(val==1)
            {
           return "首屏";
           }
           else
           {
           return "广告位";
           }
        }  
      
        function editElement(id)
        {
               global.id=id;
              $.ajax({ type: "GET",
                url: "/banner/getelement?id="+id,
                success: function(data)
                 {
                    var returnData=jQuery.parseJSON(data);
                    if(returnData.code==0)
                    {
                     $('#dlg').dialog('open');
                     var element=returnData.data;
                     $("#title").textbox("setValue",element[0].title);
                     $("#display_img_banner").attr("src",element[0].url);
                     $("#content_target").textbox("setValue",element[0].intent_data);
                     $("#content_type").combobox("setValue",element[0].intent_type);
                     $("#form_upload_banner").hide();
                     $("#form_upload_successful_banner").show();
                     if(element[0].pic_type==1){
                        $("#img_flag").val(1);
                     }else{
                         $("#img_flag").val(0);
                     }
                     
                    }
              
                  }});
        }
        
         </script>
    
</body>
</html>